const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    GQ_classid:0,
    GQ_IndexId:'',
    GQ_Lev:1,
    className:'',
    classList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this 
    var url = 'api/FeijiuApp/GetMyFabuGqClassList?GQ_IndexId=&GQ_Lev=1&strRSA=';
    app.getDaoGet(url,function (r) {
      if (r.code == 200) {
        that.setData({
          classList:r.data
        })
      }      
    })
  },

  select:function (e) {
    if (e.currentTarget.dataset.gq_indexid == 0) {
      this.dataChange();
    }else{
      var name = this.data.className;
      name+=e.currentTarget.dataset.classname+'>>';  
      this.setData({
        GQ_classid:e.currentTarget.dataset.gq_classid,
        GQ_IndexId:e.currentTarget.dataset.gq_indexid,
        GQ_Lev:e.currentTarget.dataset.gq_lev+1,
        className:name   
      })
      this.getClassList()
    }


  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {
  
  // },
  getClassList:function () {
    var that = this
    var url = 'api/FeijiuApp/GetMyFabuGqClassList?GQ_IndexId='+this.data.GQ_IndexId+'&GQ_Lev='+this.data.GQ_Lev+'&strRSA=';
    app.getDaoGet(url,function (r) {
      if (r.code == 200) {
        if (r.data.length > 0) {
          var arr = [{GQ_classid: 0, GQ_IndexId: 0, GQ_Lev: 0, gq_classname: "不限"}].concat(r.data);
          that.setData({
            classList:arr
          })          
        }else{          
          that.dataChange();
        }
      }      
    })    
  },
  dataChange:function () {
    var name = this.data.className;
    // var gq_classid1 = gq_classid.substring(0,gq_classid.length -1);
    var naem1 = name.substring(0,name.length -2);
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2];     
    prevPage.setData({
      typename:naem1,
      GQ_classid:this.data.GQ_IndexId
    })
    wx.navigateBack();    
  }
})